Question: In a class of $40$ students, $18$ said they liked apple pie, $15$ said they liked chocolate cake, and $12$ said they did not like either. How many students in the class liked both?
Of the $40$ students, $12$ did not like either dessert. Therefore, $40-12=28$ students liked at least one of the desserts. But $18$ students said they liked apple pie, $15$ said they liked chocolate cake, and $18+15=33,$ so $33-28=\boxed{5}$ students must have liked both of the desserts.